// packageA/member/taiWithdraw/taiWithdraw.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // toi: this.fun.getKeyByI(),
    datas: [],
    typeData: [],
    popupSpecs: false,
    taiValue: '',
    sType: "", //筛选规格

    loading: false,
    allLoaded: false,
    goload: true,
    isLoadMore: true,
    page: 1,
    total_page: 0,

    income_name_text: "",
    isLoading: false,
    top: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // this.data.toi = this.fun.getKeyByI();
    // this.data.sType = ""; //初始化
    // this.initData();
    // //获取数据
    // this.getData();
    const res = wx.getMenuButtonBoundingClientRect()
    console.log(res.top)
    this.setData({
      top: res.top * 2
    })
    this.getList();
  },
  fanhui(){
    wx.reLaunch({
      url: '/packageG/pages/member/extension/extension',
    })
  },
  getList(){
    let _this = this
    wx.request({
      url: 'https://shops.cg500.com/addons/yun_shop/api.php?i=8&type=2&route=YuZong.user_tai', // 接口的URL地址
      method: 'POST', // 请求方法，可以是GET、POST等
      data: {
        // 需要发送给接口的数据，根据接口要求进行定义
        uid: wx.getStorageSync('uid'),
        // uid: '20205',
        // goods_id: '3040',
      },
      success(res) {
        // 接口请求成功的回调函数
        console.log(res); // 打印接口返回的数据
        
        if (response.result == 1) {
          // that.total_page = response.data.last_page;
          _this.setData({
            datas: response.data,
          });
          // that.datas = response.data;
          // that.isLoading = false;
        } else {
          // that.isLoading = false;
          // console.log(response.msg);
        }
       
      
      },
      fail(res) {
        // 接口请求失败的回调函数
        console.error(res.errMsg); // 打印错误信息
      },
    });
  },
  tixianAll() {
    this.taiValue = this.datas.tai
  },
  tixian() {
    let that = this;
    let json = {
      uid: localStorage.getItem("uid"),
      num: this.taiValue
    };
    that.isLoadMore = false;
    $http.post("YuZong.tixian", json, "加载中...").then(
      function (response) {
        console.log(response, 'YuZong.tixian');
        that.isLoadMore = true;
        if (response.result == 1) {
          // that.total_page = response.data.last_page;
          // that.datas = response.data;
          that.isLoading = false;
          that.popupSpecs = false;
          that.getData();
          that.taiValue = ''

        } else {
          that.isLoading = false;
          Toast(response.msg);
          console.log(response.msg);
        }
      },
      function (response) {
        console.log(response);
      }
    );
  },
  getData() {
    let that = this;
    let json = {
      uid: localStorage.getItem("uid")
    };
    that.isLoadMore = false;
    $http.get("YuZong.user_tai", json, "加载中...").then(
      function (response) {
        console.log(response, 'YuZong.user_tai');
        that.isLoadMore = true;
        if (response.result == 1) {
          // that.total_page = response.data.last_page;
          that.datas = response.data;
          that.isLoading = false;
        } else {
          that.isLoading = false;
          console.log(response.msg);
        }
      },
      function (response) {
        console.log(response);
      }
    );
  },
  openPopup() {
    this.popupSpecs = true
  },
  cancelPopup() {
    this.popupSpecs = false
  },
  //初始化数据
  initData() {
    this.page = 1;
    this.total_page = 0;
    this.goload = true;
    this.loading = true;
    this.allLoaded = false;
    this.isLoadMore = true;
    this.datas = [];
  },

  //更新
  loadTop() {
    this.initData();
    this.getData(this.sType);
    // this.$refs.coupon_loadmore.onTopLoaded();
  },
  // 加载更多
  //获取数据
  // getData() {
  //   let that = this;
  //   let json = { income_type: this.sType, page: this.page };
  //   that.isLoadMore = false;

  // //   $http.get("finance.income.get-income-list", json, "加载中...").then(
  // //     function(response) {
  // //       // console.log(response);
  // //       that.isLoadMore = true;
  // //       if (response.result == 1) {
  // //         that.total_page = response.data.last_page;
  // //         that.datas = response.data.data;
  // //         that.isLoading = false;
  // //       } else {
  // //         that.isLoading = false;
  // //         console.log(response.msg);
  // //       }
  // //     },
  // //     function(response) {
  // //       console.log(response);
  // //     }
  // //   );
  // $http.get("finance.income.get-shou-yi", json, "加载中...").then(
  //     function(response) {
  //       console.log(response,'finance.income.get-shou-yi');
  //       that.isLoadMore = true;
  //       if (response.result == 1) {
  //         // that.total_page = response.data.last_page;
  //         that.datas = response.data;
  //         that.isLoading = false;
  //       } else {
  //         that.isLoading = false;
  //         console.log(response.msg);
  //       }
  //     },
  //     function(response) {
  //       console.log(response);
  //     }
  //   );
  // },

  //获取更多
  getMoreData() {
    var that = this;
    that.isLoadMore = false;
    if (this.page >= this.total_page) {
      return;
    } else {
      this.page = this.page + 1;
      $http
        .get(
          "finance.income.get-income-list", {
            income_type: this.sType,
            page: this.page
          },
          "加载中..."
        )
        .then(
          function (response) {
            that.isLoadMore = true;
            if (response.result == 1) {
              var myData = response.data;
              that.loading = false;
              that.allLoaded = false;
              that.datas = that.datas.concat(myData.data); //数组拼接
            } else {
              that.page = that.page - 1;
              that.loading = true;
              that.allLoaded = true;
              that.isLoadMore = false;
              return;
            }
          },
          function (response) {
            // error callback
          }
        );
    }
  },

  //获取类型数据
  getTypeData() {
    let that = this;
    let json = {
      i: this.fun.getKeyByI(),
      type: this.fun.getTyep()
    };
    $http.get("finance.income.get-search-type", json, "获取中...").then(
      function (response) {
        // console.log(response);
        if (response.result == 1) {
          that.typeData = response.data;
          that.popupSpecs = true;
        } else {
          console.log(response.msg);
        }
      },
      function (response) {
        console.log(response);
      }
    );
  },

  //返回
  goto() {
    window.history.go(-1);
  },

  //筛选
  screen() {
    if (this.typeData.length == 0) {
      this.getTypeData();
    } else {
      this.popupSpecs = true;
    }
  },
  //点击筛选处理
  screenType(_type) {
    this.sType = _type;
    this.popupSpecs = false;
    this.initData();
    this.getData();
  },
  //自定义提现收入语言
  customizeIncome() {
    let mailLanguage = this.fun.initMailLanguage();
    //自定义收入字段
    this.income_name_text = mailLanguage.income.income_name;
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})